package com.dongqi.actionRecord.controller;

import com.dongqi.actionRecord.dto.ActionRecordDetailDTO;
import com.dongqi.actionRecord.service.ActionRecordService;
import com.dongqi.utils.RestResult;
import com.dongqi.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping(value = "/actionRecord")
public class ActionRecordController {
    @Autowired
    private ActionRecordService actionRecordService;

    @GetMapping("/queryAll")
    public RestResult queryAll() {
        Map<String, Object> actionRecordDetailDTOList = actionRecordService.queryAll();
        return RestResult.success(actionRecordDetailDTOList);
    }

    @PostMapping("/queryByBehaviorType")
    public RestResult queryByBehaviorType(@RequestBody Map<String, String> map) {
        if (null == map.get("behaviorType") || StringUtils.isEmpty(map.get("behaviorType"))) {
            return RestResult.error("传入参数有误");
        }
        List<ActionRecordDetailDTO> actionRecordDetailDTOList = actionRecordService.queryByBehaviorType(map.get("behaviorType"));
        return RestResult.success(actionRecordDetailDTOList);
    }
}
